home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
098
/
adjram30.arc
/
ADJRAM.DOC
next >
Wrap
Text File
|
1986-09-18
|
41KB
|
845 lines
ADJRAM -- Adjustable RAM Disk
by Gary Cramblitt
Version 3.0
(c) Copyright 1986 by Gary Cramblitt. All rights reserved.
Permission is granted to copy and use this software for
non-commercial purposes only.
NOTICE: This program is provided on an "as is" basis
without warranty of any kind, expressed or implied,
including but not limited to the implied warranties of
mercantability and fitness for a particular purpose. The
entire risk as to quality and performance of this program is
with you, the user. Should the program prove defective, you
assume the entire cost of all necessary repair, servicing,
or correction. In no event will the author be liable to you
for any damages, including any lost profits, lost savings,
or other incidental or consequential damages arising out of
the use or inability to use this program.
This program, although copyrighted, may be freely copied and
used, so long as it is not used for commercial purposes. It is
NOT shareware or user-supported software. You are not expected
to make a donation to the author for using this program. Enjoy
-- and try to do the same for others some day.
What Is ADJRAM?
---------------
ADJRAM is a RAM disk program. Sometimes, RAM disks are called
"virtual disks" like the VDISK supplied with PC-DOS. Sometimes
they are called "memory disks" like MEMBRAIN. Whatever you call
it, a RAM disk is a program that makes a section of the Random
Access Memory (RAM) of your computer look like a floppy disk
drive to DOS. The advantage is that RAM is many hundreds of
times faster than a floppy disk -- even faster than a hard disk.
Why use ADJRAM, when you already have VDISK or MEMBRAIN or some
other RAM disk? Because ADJRAM allows you to vary the size of
the RAM disk without rebooting, and without loss of existing
data stored in the RAM disk. For example, you can start out
with 64K of your memory allocated for the RAM disk, expand it
later to 320K, copy a document file of 60K to the RAM disk, and
still later reduce the RAM disk capacity back down to 128K --
without losing your document file.
ADJRAM is ideal for those who do not have a hard disk.
Requirements
------------
ADJRAM is designed to run under MS-DOS version 2 or greater. It
has been tested on the following machines:
1. Zenith Z100 under MS-DOS version 2.21
2. Zenith Z171 (an IBM PC compatible) under MS-DOS version
2.11
3. KayPro 16 also under MS-DOS 2.11
4. Zenith Z158 (another IBM PC compatible) under MS-DOS
3.1 with a 2 Mbyte JRAM 3 card
It is the author's belief that it will run under PC-DOS version
2 or higher, but this has not been tested. It requires
approximately 10K bytes of disk space. Memory usage is, of
course, a function of the RAM disk's size, but it requires a
minimum of 65K free RAM.
Installation
------------
Note: If you have a computer with LOTUS/INTEL/Microsoft Expanded
Memory and you want ADJRAM to use the Expanded Memory,
please read the section below entitled "Expanded Memory
Support" before you install ADJRAM.
Copy the following files to your boot disk:
AMDISK.DVD
ADJRAM.EXE
Edit your CONFIG.SYS file and place the following line in it:
device = amdisk.dvd
Reboot your computer. If all goes well, you should see the
following message appear near the beginning of your boot
sequence:
AMDISK v3.0 (c) Copyright 1986 by Gary Cramblitt--
Initialized as disk C:
The disk drive letter will vary according to your system
configuration. Remember that drive letter, since it is that
disk which is your RAM disk.
If you use any memory resident programs, such as Sidekick (a
trademark of Borland International), load them before attempting
to change the size of the RAM disk (as explained in the next
section).
Using the RAM Disk
------------------
The RAM disk is used just like any floppy disk drive. You can
copy files to or from it, create directories on it, erase files,
etc. You may NOT do the following things with the RAM disk:
1. You may not FORMAT the RAM disk.
2. You may not DISKCOPY from or to the RAM disk.
3. You may not run SYS against the RAM disk.
4. You may not boot from the RAM disk.
5. You may not use any program on the RAM disk that
accesses the disk controller circuitry directly. Some
anti-copy protection programs fall into this category.
6. You may not use any program that depends upon IBM
standard disk media codes. One such program is CHKDSK.
My version of CHKDSK will report that my RAM disk is a
non-standard format and ask me if I wish to continue.
If I say yes, everything works normally thereafter.
Restrictions 1 through 5 are generally true of any RAM disk.
Restriction 6 is unique to the Adjustable RAM Disk because it
uses a non-standard disk media code. This shouldn't cause great
hardship though.
Also, keep in mind that anything stored in the RAM disk can
potentially be lost. For example, should your power fail and
you don't have an Uninterruptible Power Source (UPS), then
everything in the RAM disk will be lost. If you reboot (by
pressing CTRL-ALT-DEL for example), the contents of the RAM disk
are lost. It is a good idea to periodically copy important
files to a more permanent medium, such as floppy disk.
The RAM disk defaults to a size of 64K bytes when you first boot
the system. The ADJRAM program is used to change this size.
For example, to increase the size of the RAM disk by 64K bytes,
enter the following command to the DOS prompt:
ADJRAM C: +64
The spaces after "ADJRAM" and after "C:" are required. The
drive letter (C:) will vary according to your system's
configuration. Use whatever letter was displayed by AMDISK when
you booted the system.
When ADJRAM is run, you should see something like this displayed
on your screen:
Adjust Memory Disk (c) Copyright 1986 by Gary Cramblitt
Drive C: Total Size: 64K Free Space: 61K
Desired Size: 128K Desired Change: 64K
Allocating new 32K memory block #1
Allocating new 32K memory block #2
Memory Block Table
Block # Paragraph Size(sectors)
-------- --------- -------------
0 604 128
1 26A9 64
2 2EAA 64
The drive letter displayed will vary, as I've already explained.
The exact paragraph numbers will also vary according to your
system configuration and whatever other software is loaded.
ADJRAM always increments its size in 32K junks, called "memory
blocks". The change you specify is always rounded up to the
next closest multiple of 32. In the example above, two new 32K
memory blocks are created for the additional 64K of space. The
Memory Block Table is displayed for your information only. For
the most part, you can ignore it.
You must have sufficient free memory to allocate the additional
size. Run CHKDSK if you are unsure about how much free memory
you have.
You can also shrink the RAM disk. For example, the following
command would decrease the size of the RAM disk by 32K:
ADJRAM C: -32
You must have sufficient free space in the RAM disk in order to
shrink it. To find out how much free space you have in the RAM
disk, enter the following command:
ADJRAM C:
Notice how there is no size parameter. The program will display
the current size and free space of the RAM disk. If you have
insufficient space, you must erase enough files to get
sufficient space. Then enter your ADJRAM command again.
You can not shrink the RAM disk to less than 64K.
Instead of giving the size of the RAM disk as a plus or minus
figure, you can specify the desired size of the RAM disk like
this:
ADJRAM C: 320
This command will set the RAM disk to 320K. If it is currently
larger than 320K, it will shrink it down to 320K (provided there
is sufficient free space to do so). If it is currently smaller
than 320K, it will expand the size to 320K by allocating new
memory blocks. Remember that ADJRAM will round the figure you
specify to the next higher multiple of 32.
If you want to adjust the size of the memory disk so that it has
200K of free space, enter a command like this:
ADJRAM C: f200
Notice the letter "f" in front of the size. This command will
expand or shrink the RAM disk so as to ensure there is about
200K of free space IN THE RAM DISK.
If you want to ensure there is at least 128K of free space in
the RAM disk, enter a command like this:
ADJRAM C: m128
Notice the letter "m" in front of the size. This command will
never shrink the RAM disk, but it may expand it to make sure
there is a minimum of 128K of free space. This form of the
command is particularly handy within batch files to make sure
the RAM disk is large enough to hold a file before it is copied
into the RAM disk.
Online Help
-----------
If you can't remember the format for all these commands, fear
not. Simply enter
ADJRAM
and it will display a help message showing the formats described
above.
Hint for Floppy Disk Systems
----------------------------
If you do not have a hard disk, soon after booting your
computer, copy file ADJRAM.EXE to the RAM disk, for example:
COPY A:ADJRAM.EXE C:
You can then modify the size of the RAM disk at any time
thereafter without needing the boot disk. Just put the RAM disk
drive letter in front of any ADJRAM commands. For example:
C:ADJRAM C: -32
You can put the COPY command into your AUTOEXEC.BAT file.
Expanded Memory Support
-----------------------
ADJRAM provides limited support for LOTUS/INTEL/Microsoft
Expanded Memory (EMS version 3.2 compatible).
If you have a computer with LOTUS/INTEL/Microsoft Expanded
Memory and you want ADJRAM to use that memory, the installation
is a little different. Instead of copying ADJRAM.EXE to your
boot disk, copy file ADJRAMEM.EXE and then rename it to
ADJRAM.EXE. The rest of the installation is the same as was
described before.
If you want the program to create new memory blocks in
LOTUS/INTEL/Microsoft Expanded Memory, add a "/E" option, like
this:
ADJRAM C: +32 /E
This command will expand the memory disk by 32K. The additional
32K memory block will be created within LOTUS/INTEL/Microsoft
Expanded Memory. If ADJRAM ends up shrinking the RAM disk, the
"/E" switch is meaningless. Remember that ADJRAM will always
shrink the RAM disk by freeing memory blocks in reverse of the
order inwhich they were created.
The version of ADJRAM that supports Expanded Memory can not be
used in conjunction with the version that does not support it.
Don't get them mixed up. Use ADJRAMEM.EXE (renamed to
ADJRAM.EXE) or use ADJRAM.EXE -- but not both.
There are a couple of restrictions with the Expanded Memory
version of ADJRAM. First, some Expanded Memory systems have a
limited number of Expanded Memory handles. ADJRAM uses one
handle for each 32K Memory Block it creates. This means that
one megabyte of RAM disk from Expanded Memory will use up 32
handles. The Expanded Memory Manager provided with the JRAM 3
board I tested (JPAGER) had only 32 handles, so creating a one
megabyte RAM disk used up all of the EM handles.
Even if you have lots of EM handles, the largest RAM disk that
can be created using Expanded Memory is 2016K or about 2
Megabytes. EMS supports up to 8 Megabytes. If you want more
RAM disk, add additional "device = amdisk.dvd" statements to
your CONFIG.SYS file. This will create additional RAM disks
with different drive letters.
I'm looking for feedback from users on this feature. Is it
worth it? I suspect that most people who own Expanded Memory
boards prefer to use the RAM disk software that comes with those
boards. Right now, fixing these problems doesn't seem
worthwhile. If I'm wrong about that, please let me know.
If you think the Expanded Memory support is needed, what size
increment should it use? 128K? 256K?
The Expanded Memory support in this version of ADJRAM was coded
based on information from the book "Advanced MS-DOS" by Ray
Duncan. The code was tested on a Zenith Z158 with a 2 Mbyte
JRAM 3 memory board installed (JBOOT and JPAGER loaded). I
don't own a computer with Expanded Memory, so this part of the
program is the least tested. Please be cautious until you've
had time to thoroughly check out the program -- and let me know
if you encounter difficulty.
Error Messages
--------------
Any time that an error occurs, the phrase "Error -- " is
displayed, followed by one of the following messages. In
addition, the program sometimes displays the help message if an
error is detected -- on the assumption that you may have given
an incorrect command.
Here is a list of possible error messages you might see
displayed by the ADJRAM.EXE program and their probable cause
(the numbers in parenthesis are explained in the next section):
Error -- could not read boot sector. Error code xx (15)
The program could not read the boot sector (logical sector 0) of
the RAM disk. An invalid drive letter was specified or the RAM
disk has become corrupted. In the latter case, reboot is
recommended.
Error -- that drive is not the adjustable RAM disk. (15)
An invalid drive letter was specified. Use the letter that was
reported by AMDISK when you booted the computer. Make sure you
used the correct command syntax. A space must follow "ADJRAM".
Error -- could not free environment block. Error code xx
(7)
This error would indicate you have an incompatible version of
MS-DOS. The error codes are those returned by DOS function 49H.
Error -- Invalid drive letter or memory disk is not loaded
(15)
ADJRAM reports this error if DOS returns an error code from
function 36H (get free disk space). Check your drive letter and
command syntax.
Error -- NOT enough room to do the shrink. (0)
You do not have enough free space in the RAM disk to shrink it
by the requested amount. First erase some files from the RAM
disk, then reenter you command.
The disk is already that size! Nothing to do. (0)
You told ADJRAM to set the size to what it already is. ADJRAM
does nothing and exits. Remember that your specified size is
rounded up to the nearest multiple of 32K.
Error -- could not modify memory block size. Error code xx
(8)
This error occurs when expanding the RAM disk. The program
received an error code from DOS function 4AH (modify memory
allocation) on the first new 32K memory block to be created. It
would indicate that you don't have enough free memory to expand
the RAM disk at all. It could also be caused by corrupted
memory allocation, possibly caused by incompatibility with other
memory resident programs. Reboot is recommended in the latter
case.
Error -- could not allocate new memory block. Error code
xx (8)
This error is similar to the one above except that it occurs on
the second and subsequent new 32K memory blocks when the program
invokes DOS function 48H (allocate memory). The program will
attempt to keep going without expanding the disk any further.
This condition is not well tested though, so to be safe, reboot
is recommended.
Error -- could not allocate new memory block from EMM.
Error code xx (8)
This error is similar to the one above except that it occurs in
conjunction with creating new 32K memory blocks in
LOTUS/INTEL/Microsoft Expanded Memory. The program will attempt
to keep going without expanding the disk any further. This
condition is not well tested though, so to be safe, reboot is
recommended.
Error -- could not write boot sector back. Code: xx (15)
This is most likely an internal program error. The program got
an error code from DOS interrupt 26H (write absolute disk
sector). Reboot is required.
Error -- could not free allocated memory block #xx. Error
code xx
This error occurs when shrinking the RAM disk. The program got
an error code from DOS function 49H (release memory). Could be
caused by an internal program bug, incompatible memory resident
program, or incompatible version of DOS. The program attempts
to exit gracefully so that you can recover data files from the
RAM disk, but you should reboot as soon as possible.
Error -- could not free EM pages for memory block #xx.
Error code xx
This error occurs when shrinking the RAM disk. The program got
an error condition from the LOTUS/INTEL/Microsoft Expanded
Memory Manager. Could be caused by an internal program bug,
incompatible memory resident program, or incompatible version of
DOS. The program attempts to exit gracefully so that you can
recover data files from the RAM disk, but you should reboot as
soon as possible.
Error -- Insufficient stack space to pack subdirectory
xxxxxxxx. Too many subdirectories. Shrink abandoned. (8)
This error occurs when shrinking the RAM disk. The DeSmet C
stack space was insufficient to handle the depth of
subdirectories you have on your RAM disk. The program attempts
to exit gracefully without completing the shrink. This
condition has not been fully tested, so caution, your files may
have been corrupted. In the future, don't use so many
subdirectories.
Error -- Expanded Memory Manager is not avaiable.
Error code: xx (15)
You specified the "/E" option, but the LOTUS/INTEL/Microsoft
Expanded Memory Manager (EMM) is not loaded. Load the EMM and
try again.
Error -- Expanded Memory Manager could not report page
frame. Error code: xx (8)
The EMM was detected by ADJRAM, but the EMM reported an error
when ADJRAM asked for the page frame segment address (EMM
function 41H). This could be caused by a corrupted EMM, or an
incompatible version of the EMM (ADJRAM requires version 3.2
compatibility), or possibly ADJRAM encountered a "busy"
condition from the EMM. Try again. If it still fails, you'll
have to stick with normal memory.
There are two other conditions which do not display an error
message. In these cases, the program simply displays the help
message and exits:
1. Invalid drive letter specified. Must be in range A
through I. (15)
2. Invalid size specified. Must be in range 64 to 2016.
(1).
There are also a large number of possible errors that MS-DOS will
display while you're working with the RAM disk. Consult your
DOS manual. One message I'd like to point out. If you see
Bad File Allocation Table
(or something similar) the RAM disk is probably corrupted.
Carefully check your files. If they are OK, copy them to a more
permanent medium, such as floppy disk, then reboot.
Using ADJRAM in Batch Files
---------------------------
If an error occurs while running ADJRAM, it will return a DOS
error code when it exits back to DOS. The error codes returned
are shown in parenthesis in the error message section above.
These error codes can be used in a batch file via the DOS
ERRORLEVEL subcommand. See your DOS manual.
Some versions of MS-DOS (Z100 v2.21 for example) have a command
which will cause error codes to be displayed. It is:
XYZZY ON
Compatibility and Memory Usage
------------------------------
The Adjustable RAM Disk falls into a class of programs known as
Memory Resident programs. Sidekick is one such program. These
programs are sometimes incompatible with one another. It is
impossible for me to test the Adjustable RAM disk in combination
with every available memory resident program, so I'll apologize
ahead of time -- some incompatibilities are almost certain to
crop up.
Sometimes, changing the order inwhich the programs are loaded
makes a difference.
Generally, you should load all of your memory resident programs
BEFORE you run ADJRAM. (I know, every memory resident program
wants to be loaded last, but please bear with me!) You should
do this to make the most efficient use of memory. Here's why.
When you expand the RAM disk, ADJRAM allocates 32K memory blocks
using the DOS memory allocation functions. Once that is done,
any subsequent memory resident programs you load will generally
get loaded above these new memory blocks. When you later shrink
the RAM disk, ADJRAM deallocates the memory blocks. If you have
loaded a memory resident program after expanding the RAM disk
with ADJRAM, then "holes" in the memory allocation will be
created when you later shrink the RAM disk. These holes will
generally not be usable for transient programs until you unload
the memory resident program (which might not even have that
capability).
You generally shrink the RAM disk because you want to make more
memory available for other programs. But it defeats this
objective to load memory resident programs after expanding the
RAM disk. So...
First load the memory resident programs, then use ADJRAM to
expand your RAM disk.
The Adjustable RAM disk doesn't "steal" interrupts from the
system, so expanding the RAM disk after loading programs that
intercept interrupts, such as Sidekick, SHOULDN't cause any
problems.
If you encounter compatibility problems, please let me know at
the address I'll give at the end of this document. I'd like to
know about them so I can fix them if possible. Please be as
complete as possible when you explain the problem. What memory
resident programs did you have loaded and in what order? How
much memory do you have in your computer? What computer and
operating system were you running? Exactly what happened when
it didn't work? I won't guarantee that I can fix the problem,
but I'll try.
Known Compatibility Problems
----------------------------
When using ADJRAM with DoubleDOS, new memory blocks are created
within whichever partition is active at the time you run ADJRAM.
If you attempt to shrink the RAM disk to gain additional room in
the first partition, you may find that you didn't gain any room
in the first partition! Instead, the room gained was in the
second partition (because that's where the memory blocks were
created).
Also, DoubleDOS doesn't know about ADJRAM creating new memory
blocks. This causes DoubleDOS to tell you there is more room in
partitions than actually exists. Use CHKDSK to find out how big
your partitions really are. In general, you should try to run
ADJRAM before activating DoubleDOS, to avoid this problem.
ADJRAM is somewhat incompatible with MARK/RELEASE. You can't
expand the RAM disk after you've run MARK, because when you run
RELEASE, AMDISK won't know that some of its memory blocks have
been freed. As long as you expand before you run MARK for the
first time, you should be OK. I have not tried MARK/RELEASE in
conjunction with ADJRAM, so there may be other problems as well.
The Referee, being a program similar to MARK/RELEASE, will
problably also have these problems.
Other Known Problems
--------------------
If you expand the RAM disk into all available memory, you will
probably die. You can't get enough room to run ADJRAM again so
as to shrink it back down. The program does not check to see if
you're expanding the RAM disk into all free memory, so be
careful.
By the way, the coding fix to this problem is not as simple as
you might think (my Z100 has 768K of user memory, not 640K.
What about Expanded Memory? etc.). If someone can tell me a
fullproof way to determine how much free memory exists, let me
know.
Some programs, such as PC-WRITE have a "shell" or "hotkey"
command that allows you to suspend the program, keeping it in
memory, and execute other DOS commands. You may be tempted to
use this capability to increase or decrease the size of the RAM
disk in the middle of running another program. But be careful
here. Consider the following sequence of events:
1. You're running PC-WRITE, editing file C:MYFILE.DOC on
the RAM disk.
2. You use PC-WRITE's "shell" command to get the DOS
prompt.
3. You use ADJRAM to expand the size of disk C, the RAM
disk.
4. You use the DOS EXIT command to go back into PC-WRITE.
5. Upon exiting PC-WRITE, you're horrified to learn that
it was unable to successfully save all your work in
C:MYFILE.DOC.
The problem here is that ADJRAM told DOS that the "media has
changed" on disk C. But PC-WRITE had a file open on disk C!
DOS can't properly close the file. This sort of problem will
generally occur with any program that has a "shell" command but
fails to close all open files before executing the shell. [By
the way, I haven't actually checked that PC-WRITE does keep
files open. It may well be that there is no problem. Indeed,
it would surprise me to learn that PC-WRITE does have this
problem. PC-WRITE is a dynamite program!]
This kind of problem can also occur with certain memory resident
programs that, in effect, give you a "shell" command from within
any program.
Remember that whenever you expand or shrink the RAM disk, you
have, conceptually, removed the current "floppy disk" in the RAM
drive, and replaced it with another "floppy disk" that just
happens to have the same files as the one removed. You wouldn't
change a real floppy disk in the middle of editing a Wordstar
file, so don't expand or shrink the RAM disk either.
Planned Enhancements
--------------------
I'm planning on making the following enhancements at some time
in the future:
1. Fix the problem mentioned above about expanding into
all available memory.
2. Allow the initial RAM disk size to be specified at boot
time in the CONFIG.SYS file, like this
device = amdisk.dvd SIZE=32
If you can think of other useful enhancements, let me know about
them please.
History
-------
This is the first version of ADJRAM to be released. It was
released to the public in September 1986.
Internals
---------
This section is for anyone interested in the internal workings
of the Adjustable RAM Disk. It is not necessary to know this
information to use the Adjustable RAM Disk, but it may be
helpful for resolving compatibility problems. This section is
for advanced DOS programmers only.
AMDISK.DVD is a loadable device driver, just like VDISK or
ANSI.SYS. By itself, it is a complete 64K RAM disk. A 64K
"memory block" is allocated immediately after the AMDISK code.
A Memory Block Table is maintained in logical sector 0 (the boot
sector) of the RAM disk beginning at offset 1EH. For each
memory block, this table contains a seven byte entry as follows:
1. A byte indicating the type of memory block. 0 means
the block is allocated in normal DOS memory. 1 means
the block is allocated in Expanded Memory.
2. A word giving the starting paragraph number of the
memory block. A paragraph of memory is simply 16
bytes, so this number is just the absolute memory
address shifted right by 4 bits. All memory blocks
begin on an even paragraph boundary. This word is zero
if there are no more memory blocks. It is meaningless
for Expaned Memory blocks.
3. A word giving the size of the memory block in 512-byte
sectors.
4. A word giving the Expanded Memory handle for the memory
block. Zero for normal memory blocks.
Immediately after booting, there is exactly one 64K (128 sector)
memory block in the Memory Block Table.
Note: Don't confuse the memory blocks defined here with those
defined for DOS functions 48H thru 4AH. To avoid
confusion -- and though not strictly accurate -- I'll
refer to DOS's memory blocks as "program segments".
The number of memory blocks allocated is stored in the media
descriptor byte at offset 15H of the boot sector (and also in
the first FAT entry). Any time DOS requests a media code from
the AMDISK device driver, it returns the number of memory blocks
allocated. In this way, any time that the RAM Disk has been
shrunk or expanded, DOS will know that the "media has changed"
and will rebuild its internal BPB tables. This lets DOS know
what the new size of the RAM disk is.
Upon startup of the ADJRAM program, DOS function 49H (release
memory) is used to deallocate its own environment segment. This
doesn't seem to hurt a running program, and it is necessary to
insure that this memory can be used later when the RAM disk is
shrunk.
At startup, the Expanded Memory version of ADJRAM tests whether
the Expanded Memory Manager (EMM) is loaded by opening device
"EMMXXXX0". If the open fails, the EMM is not loaded. If the
open succeeds, then the output status is requested from the
device using DOS function 44H (IOCTL). If IOCTL reports a
status of 0, then coincidentally a file named "EMMXXXX0" existed
on the default disk, and the EMM is still not available. If the
EMM is not available, ADJRAM reports an error and exits.
Also upon startup, ADJRAM checks that the specified drive letter
corresponds to the AMDISK device. The boot sector of the RAM
disk contains the string "AMDISK" at offset 03H. The boot
sector is read using DOS interrupt 25H (absolute disk read).
When the ADJRAM program increases the size of the RAM disk, it
does so by allocating additional 32K (64 sector) memory blocks.
Normal memory blocks are allocated in two ways:
1. If it is the first memory block to be created (in this
run of ADJRAM), then the memory block is allocated
using DOS function 4AH (modify memory allocation).
ADJRAM's own program segment is the one modified.
Hence, the first memory block overwrites the ADJRAM
program itself.
2. Additional memory blocks are allocated using DOS
function 48H (allocate memory).
In either case, an appropriate entry is made in the Memory Block
Table, which is in the boot sector, for each new memory block.
At the end of the program, the boot sector is written back out
using DOS interrupt 26H (absolute disk write).
When ADJRAM exits normally, it uses DOS function 31H (terminate
and stay resident) to permanently allocate the new memory
blocks.
Expanded Memory blocks are allocated via EMM function 43H (Get
handle and allocate memory).
When ADJRAM shrinks the RAM disk, it does these steps:
1. It checks to insure there is sufficient free space in
the RAM disk to do the shrink.
2. The File Allocation Table (FAT) is read using DOS
interrupt 25H. The first available cluster number is
determined.
3. The first sector of the directory is read in using DOS
interrupt 25H.
4. For each file, any clusters located after the first
available cluster are moved down to the first available
cluster. Then the next available cluster is
determined. If the file is a subdirectory, then this
packing routine (steps 3 thru 5) is recursively called.
Clusters are moved in the RAM disk using DOS interrupts
25H and 26H. As clusters are moved, the directory and
FAT in memory are updated.
5. Step 4 is repeated for each additional directory
sector. Updated directory sectors are written back to
the disk using DOS interrupt 26H.
6. The necessary number of memory blocks are deallocated,
either using DOS function 49H (release memory) or EMM
function 45H (release handle and memory). The Memory
Block Table is updated accordingly. Blocks are
deallocated in reverse of the order inwhich they are
created.
7. The updated FAT and boot sector are written back to the
disk using DOS interrupt 26H.
8. ADJRAM exits normally via DOS function 4CH (exit with
return code).
An excellent book for understanding DOS memory allocation and
disk structure is the "MsDOS Developer's Guide", written by the
Waite Group and published by SAMS. Another excellent book,
which includes documentation on Expanded Memory, is "Advanced
MS-DOS" by Ray Duncan.
In the course of developing this program, I discovered a couple
of interesting things about the DOS version 2 memory allocation
functions (48H thru 4AH).
1. Transient programs are always loaded after the last
allocated memory block, even if there is sufficient
memory available in "holes" below the last allocated
memory block. Such holes could be created by loading a
memory resident program, such as Sidekick, and then
shrinking the RAM disk.
2. The allocate memory function (48H), on the otherhand,
will use holes if they exist and if they are large
enough to contain the requested block.
3. If a program modifies a DOS memory block (function
4AH), it becomes the "owner" of that block, even if it
didn't create the block in the first place. When such
a program exits, the block will be automatically
deallocated by DOS unless the program exits via
terminate and stay resident. This is why ADJRAM must
allocate memory blocks in fixed 32K increments.
Ideally, it should allocate exactly the requested size
and no more. The DOS quirk described here prevents
that though.
The source code for the Adjustable RAM Disk is included with the
program. AMDISK.DVD is coded in MASM; ADJRAM.EXE is coded in
DeSmet C version 2.4. Even though I've included the source
code, I would nevertheless like to act as the clearinghouse for
all future versions and modifications. If you make a change to
the program, or fix a bug, PLEASE let me know about it -- I may
want to include the change in future versions.
If you modify the program, you agree to maintain my copyright.
You should indicate that you've modified the program by changing
the version number, for example "version 3.0A", or by putting
some other distinguishing message in the signon of the program,
for example "custom version by John Doe". The rational for this
is simple -- I don't won't to be blamed for your bug.
My address, as of September 1986 is:
GARY CRAMBLITT
105 TENNESSEE RD
STEVENSVILLE, MD 21666
Please do not telephone. I'd like to receive your letter.
* * * * END OF ADJRAM.DOC * * * *